package de.duester.genealogy.model.service;

import java.util.ArrayList;
import java.util.List;

import de.duester.genealogy.model.Document;
import de.duester.genealogy.model.Event;
import de.duester.genealogy.model.EventDocument;
import de.duester.genealogy.model.Person;
import de.duester.genealogy.model.PersonDocument;
import de.greenrobot.dao.DaoException;

public class DocumentService {

	public static List<Person> getPersons(Document document) {
		List<Person> list = new ArrayList<Person>();
		try {
			for (PersonDocument pd : document.getPersonDocuments())
				if (!list.contains(pd.getPerson()))
					list.add(pd.getPerson());
		} catch (DaoException e) {
		}
		return list;
	}

	public static List<Event> getEvents(Document document) {
		List<Event> list = new ArrayList<Event>();
		try {
			for (EventDocument ed : document.getEventDocuments())
				if (!list.contains(ed.getEvent()))
					list.add(ed.getEvent());
		} catch (DaoException e) {
		}
		return list;
	}

	public static List<Event> getEvents(Document document, String typeCode) {
		List<Event> list = new ArrayList<Event>();
		List<Event> events = getEvents(document);
		for (Event event : events)
			if (event.getTypeCode().equals(typeCode))
				list.add(event);
		return list;
	}
}
